package cn.tmpan.project.common.enums;

/**
 * 返回字段代码信息
 *
 * @Author tieminPan
 * @Description
 * @Date 2018 /9/23 22:32
 * @Param
 * @return
 */
public enum ResponseCode {


    /**
     * Success response code.
     *
     * @desc 请求操作成功
     */
    SUCCESS(0, "操作成功!"),
    /**
     * Error response code.
     *
     * @desc 请求操作失败
     */
    ERROR(1, "操作失败!"),
    /**
     * Illegal argument response code.
     *
     * @desc 参数错误
     */
    ILLEGAL_ARGUMENT(2, "请求参数错误!"),
    /**
     * Need login response code.
     *
     * @desc 需要登录
     */
    NEED_LOGIN(50000, "登录超时,请重新登录!"),
    /**
     * Exception response code.
     *
     * @desc 服务器内部错误
     */
    EXCEPTION(500, "该请求发生异常,请稍后重试!"),
    /**
     * Sys not found error response code.
     */
    SYS_NOT_FOUND_ERROR(404, "未找到相应资源!"),

    DATABASE_ERROR(6000,"数据库异常,请稍后重试!"),
    /**
     * Sys not use error response code.
     */
    SYS_NOT_USE_ERROR(403, "资源不可用!");


    private final int code;
    private final String desc;


    ResponseCode(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * Gets code.
     *
     * @return the code
     */
    public int getCode() {
        return code;
    }

    /**
     * Gets desc.
     *
     * @return the desc
     */
    public String getDesc() {
        return desc;
    }


    public static ResponseCode codeOf(int code) {
        for (ResponseCode s : values()) {
            if (s.code == code) {
                return s;
            }
        }
        throw new RuntimeException("没有找到对应的枚举");
    }
}
